#![feature(test)]

extern crate test;

use test::Bencher;
use rcrypto::{DES, Cipher};

#[bench]
fn des(b: &mut Bencher) {
    b.iter(|| {
        let cases = [
            ([0x00u8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0x00u8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0x8cu8, 0xa6, 0x4d, 0xe9, 0xc1, 0xb1, 0x23, 0xa7],),
            ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0x35, 0x55, 0x50, 0xb2, 0x15, 0x0e, 0x24, 0x51],),
            ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x61, 0x7b, 0x3a, 0x0c, 0xe8, 0xf0, 0x71, 0x00]),
            ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0x92, 0x31, 0xf2, 0x36, 0xff, 0x9a, 0xa9, 0x5c]),
            ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0xca, 0xaa, 0xaf, 0x4d, 0xea, 0xf1, 0xdb, 0xae]),
            ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0x73, 0x59, 0xb2, 0x16, 0x3e, 0x4e, 0xdc, 0x58]),
            ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x6d, 0xce, 0x0d, 0xc9, 0x00, 0x65, 0x56, 0xa3]),
            ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0x9e, 0x84, 0xc5, 0xf3, 0x17, 0x0f, 0x8e, 0xff]),
            ([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0xd5, 0xd4, 0x4f, 0xf7, 0x20, 0x68, 0x3d, 0x0d]),
            ([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0x59, 0x73, 0x23, 0x56, 0xf3, 0x6f, 0xde, 0x06]),
            ([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x56, 0xcc, 0x09, 0xe7, 0xcf, 0xdc, 0x4c, 0xef]),
            ([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0x12, 0xc6, 0x26, 0xaf, 0x05, 0x8b, 0x43, 0x3b]),
            ([0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
             [0xa6, 0x8c, 0xdc, 0xa9, 0x0c, 0x90, 0x21, 0xf9]),
            ([0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
             [0x2a, 0x2b, 0xb0, 0x08, 0xdf, 0x97, 0xc2, 0xf2]),
            ([0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0xed, 0x39, 0xd9, 0x50, 0xfa, 0x74, 0xbc, 0xc4]),
            ([0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10],
             [0xa9, 0x33, 0xf6, 0x18, 0x30, 0x23, 0xb3, 0x10]),
            ([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
             [0x17, 0x66, 0x8d, 0xfc, 0x72, 0x92, 0x53, 0x2d]),
            ([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef],
             [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01],
             [0xb4, 0xfd, 0x23, 0x16, 0x47, 0xa5, 0xbe, 0xc0]),
            ([0x0e, 0x32, 0x92, 0x32, 0xea, 0x6d, 0x0d, 0x73],
             [0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87],
             [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
            ([0x73, 0x65, 0x63, 0x52, 0x33, 0x74, 0x24, 0x3b], // "secR3t$;"
             [0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x31, 0x32], // "a test12"
             [0x37, 0x0d, 0xee, 0x2c, 0x1f, 0xb4, 0xf7, 0xa5]),
            ([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68], // "abcdefgh"
             [0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68], // "abcdefgh"
             [0x2a, 0x8d, 0x69, 0xde, 0x9d, 0x5f, 0xdf, 0xf9]),
            ([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68], // "abcdefgh"
             [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38], // "12345678"
             [0x21, 0xc6, 0x0d, 0xa5, 0x34, 0x24, 0x8b, 0xce]),
            ([0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38], // "12345678"
             [0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68], // "abcdefgh"
             [0x94, 0xd4, 0x43, 0x6b, 0xc3, 0xb5, 0xb6, 0x93]),
            ([0x1f, 0x79, 0x90, 0x5f, 0x88, 0x01, 0xc8, 0x88], // random
             [0xc7, 0x46, 0x18, 0x73, 0xaf, 0x48, 0x5f, 0xb3], // random
             [0xb0, 0x93, 0x50, 0x88, 0xf9, 0x92, 0x44, 0x6a]),
            ([0xe6, 0xf4, 0xf2, 0xdb, 0x31, 0x42, 0x53, 0x01], // random
             [0xff, 0x3d, 0x25, 0x50, 0x12, 0xe3, 0x4a, 0xc5], // random
             [0x86, 0x08, 0xd3, 0xd1, 0x6c, 0x2f, 0xd2, 0x55]),
            ([0x69, 0xc1, 0x9d, 0xc1, 0x15, 0xc5, 0xfb, 0x2b], // random
             [0x1a, 0x22, 0x5c, 0xaf, 0x1f, 0x1d, 0xa3, 0xf9], // random
             [0x64, 0xba, 0x31, 0x67, 0x56, 0x91, 0x1e, 0xa7]),
            ([0x6e, 0x5e, 0xe2, 0x47, 0xc4, 0xbf, 0xf6, 0x51], // random
             [0x11, 0xc9, 0x57, 0xff, 0x66, 0x89, 0x0e, 0xf0], // random
             [0x94, 0xc5, 0x35, 0xb2, 0xc5, 0x8b, 0x39, 0x72]),
        ];

        for ele in cases.iter() {
            let cipher = DES::new(ele.0);
            let (mut encrypt, mut decrypt) = (Vec::with_capacity(8), Vec::with_capacity(8));

            cipher.encrypt(&mut encrypt, ele.1.as_ref()).unwrap();
            cipher.decrypt(&mut decrypt, encrypt.as_slice()).unwrap();
        }
    });
}